package com.xuetang9.t9.hotel.mapper;


import com.xuetang9.t9.hotel.beans.Arrive;
import com.xuetang9.t9.hotel.mapper.condition.ICondition;
import com.xuetang9.t9.hotel.mapper.sql.impl.ArriveMapperSql;
import com.xuetang9.t9.hotel.utils.OverallConstant;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 入住信息
 * @author pang
 */
@Repository
public interface IArriveMapper {

    /**
     * 插入入住信息
     * @param arrive
     * @return
     */
    @Insert("INSERT INTO g_arrive VALUE(#{arriveId},#{roomId},#{guestId},#{peerguestId},#{ordertakerId},#{arriveDate}," +
            "#{leaveDate},#{days},#{checktypeId},#{arriveStandard},#{channel},#{onLine})")
    int insert(Arrive arrive);

    /**
     * 修改入住信息
     * @param arrive
     * @return
     */
    @Update("UPDATE g_arrive SET room_id=#{roomId},guest_id=#{guestId},peerguest_id=#{peerguestId}," +
            "ordertaker_id=#{ordertakerId},leave_date=#{leaveDate},days=#{days},checktype_id=#{checktypeId},arrive_standard=#{arriveStandard}," +
            "channel=#{channel},onLine=#{onLine} WHERE arrive_id=#{arriveId}")
    int update(Arrive arrive);

    /**
     * 删除入住信息
     * @param id
     * @return
     */
    @Delete("DELETE FROM g_arrive WHERE arrive_id = #{ID} ")
    int delete(Long id);

    /**
     * 根据条件查询入住信息
     * @return
     */
    @SelectProvider(value = ArriveMapperSql.class,method = "selectByAll")
    @Results(value = {
            @Result(column = "room_id",property = "roomInfo",one = @One(select = "com.xuetang9.t9.hotel.mapper.IRoomInfoMapper.selectByRoomId",fetchType = FetchType.EAGER)),
            @Result(column = "guest_id",property = "guest",one = @One(select = "com.xuetang9.t9.hotel.mapper.IGuestMapper.selectById",fetchType = FetchType.EAGER)),
            @Result(column = "peerguest_id",property = "peerGuest",one = @One(select = "com.xuetang9.t9.hotel.mapper.IGuestMapper.selectById",fetchType = FetchType.EAGER)),
            @Result(column = "ordertaker_id",property = "staffInfo",one = @One(select = "com.xuetang9.t9.hotel.mapper.IStaffInfoMapper.selectById",fetchType = FetchType.EAGER)),
            @Result(column = "checktype_id",property = "checkType",one = @One(select = "com.xuetang9.t9.hotel.mapper.ICheckTypeMapper.selectById",fetchType = FetchType.EAGER)),
    })
    List<Arrive> selectByAll(@Param("key") ICondition condition);


    /**
     * 根据客人查询在住记录表
     * @param id
     * @return
     */
    @Select("SELECT * FROM g_arrive WHERE (guest_id = #{id} OR peerguest_id = #{id}) AND onLine = 0")
    @Results(value = {
            @Result(column = "room_id",property = "roomInfo",one = @One(select = "com.xuetang9.t9.hotel.mapper.IRoomInfoMapper.selectByRoomId",fetchType = FetchType.EAGER)),
            @Result(column = "guest_id",property = "guest",one = @One(select = "com.xuetang9.t9.hotel.mapper.IGuestMapper.selectById",fetchType = FetchType.EAGER)),
            @Result(column = "peerguest_id",property = "peerGuest",one = @One(select = "com.xuetang9.t9.hotel.mapper.IGuestMapper.selectById",fetchType = FetchType.EAGER)),
            @Result(column = "ordertaker_id",property = "staffInfo",one = @One(select = "com.xuetang9.t9.hotel.mapper.IStaffInfoMapper.selectById",fetchType = FetchType.EAGER)),
            @Result(column = "checktype_id",property = "checkType",one = @One(select = "com.xuetang9.t9.hotel.mapper.ICheckTypeMapper.selectById",fetchType = FetchType.EAGER)),
    })
    List<Arrive> selectByGuestId(@Param("id") Long id);

    /**
     * 根据入住id查询一条记录
     * @param id
     * @return
     */
    @Select("SELECT * FROM g_arrive WHERE arrive_id")
    Arrive selectByOne(@Param("id") Long id);

    /**
     * 根据条件查询入住信息条数
     * @return
     */
    @SelectProvider(value = ArriveMapperSql.class,method = "selectByCount")
    Long selectByCount(@Param("key")ICondition condition);

    /**
     * 批量修改入住类型
     * @param checkTypeId
     * @return
     */
    @UpdateProvider(value = ArriveMapperSql.class,method = "update")
    int updateByCheckType(@Param("id") Integer checkTypeId);
}
